home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue30 / delcom / RegContext / RegContextMenu.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-07  |  1.8 KB  |  61 lines

  1. unit RegContextMenu;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ComObj;
  8.  
  9. type
  10.     TRegContextMenu = class(TComponent)
  11.     private
  12.         { Private declarations }
  13.         fGUID: String;
  14.         fDesc: String;
  15.         fPathName: String;
  16.         fFileType: String;
  17.     protected
  18.         { Protected declarations }
  19.     public
  20.         { Public declarations }
  21.         procedure Write;
  22.     published
  23.         { Published declarations }
  24.         property GUID: String read fGUID write fGUID;
  25.         property Description: String read fDesc write fDesc;
  26.         property PathName: String read fPathName write fPathName;
  27.         property FileType: String read fFileType write fFileType;
  28.     end;
  29.  
  30. procedure Register;
  31.  
  32. implementation
  33.  
  34. resourcestring
  35.     sBadGUID     =      'GUID string not set';
  36.     sBadDesc     =      'Description string not set';
  37.     sBadPath     =      'Pathname string not set';
  38.     sBadFileType =      'FileType string not set';
  39.  
  40. procedure TRegContextMenu.Write;
  41. begin
  42.     { Make sure everything has been set }
  43.     if fGUID = '' then raise Exception.Create (sBadGUID);
  44.     if fDesc = '' then raise Exception.Create (sBadDesc);
  45.     if fPathName = '' then raise Exception.Create (sBadPath);
  46.     if fFileType = '' then raise Exception.Create (sBadFileType);
  47.  
  48.     { CreateRegKey will raise EOleError on failure }
  49.     CreateRegKey ('CLSID\' + fGUID, '', Description);
  50.     CreateRegKey ('CLSID\' + fGUID + '\InProcServer32', '', fPathName);
  51.     CreateRegKey ('CLSID\' + fGUID + '\InProcServer32', 'ThreadingModel', 'Apartment');
  52.     CreateRegKey (fFileType + '\shellex\ContextMenuHandlers\' + fGUID, '', '');
  53. end;
  54.  
  55. procedure Register;
  56. begin
  57.     RegisterComponents ('COM', [TRegContextMenu]);
  58. end;
  59.  
  60. end.
  61.